package member.action;

import member.model.MemberInfo;
import member.dao.MemberDAO;
import java.util.Map;
import java.util.HashMap;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.ModelDriven;
import org.apache.struts2.interceptor.SessionAware;

public class LoginAction implements Action, Preparable, ModelDriven,SessionAware{

	private MemberDAO memberDAO;
	private MemberInfo memberInfo;
	private Map user;
	private Map session;
	
	public String loginForm() throws Exception{
		return SUCCESS;
	}
	
	public String execute() throws Exception {
		user = new HashMap();
		user.put("userId", memberInfo.getUserid());
		user.put("passwd", memberInfo.getPasswd());
		
		memberDAO = MemberDAO.getInstance();
		memberInfo = memberDAO.login(user);
		
		if(user == null){
			return LOGIN;
		}else{
			session.put("userId", memberInfo.getUserid());
			session.put("userName", memberInfo.getName());
			return SUCCESS;
		}		
	}
	public String LogOut()throws Exception{
		session.clear();
		return SUCCESS; 
	}

	public Object getModel() {
		return memberInfo;
	}

	public void prepare() throws Exception {
		memberInfo = new MemberInfo();		
	}

	public void setSession(Map session) {
		this.session = session;		
	}

		

}
